//
//  UIButton+Extension.swift
//  新浪微博
//
//  Created by Mac on 17/1/2.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

extension UIButton {

    // 提供新的构造方法,文字,文字颜色,文字大小, frame 信息
    convenience init(titleNormal:String, titleColorNormal:UIColor, titleFontSize:CGFloat, frame:CGRect){
        self.init()
        self.setTitle(titleNormal, for: UIControlState.normal)
        self.setTitleColor(titleColorNormal, for: UIControlState.normal)
        self.titleLabel?.font = UIFont.systemFont(ofSize: titleFontSize)
        self.frame = frame
    }
    
    // 提供文字及高亮文字,高亮颜色,
    convenience init(titleNormal:String, titleHighlighted:String, titleColorNormal:UIColor, titleColorHighLighted:UIColor,titleFontSize:CGFloat,frame:CGRect){
        self.init()
        self.setTitle(titleNormal, for: UIControlState.normal)
        self.setTitle(titleHighlighted, for: UIControlState.highlighted)
        self.setTitleColor(titleColorNormal, for: UIControlState.normal)
        self.setTitleColor(titleColorHighLighted, for: UIControlState.highlighted)
        self.titleLabel?.font = UIFont.systemFont(ofSize: titleFontSize)
        self.frame = frame
    }
    
    // 提供构造方法,背景图
    convenience init(backgroundImageNormal:UIImage,backgroundImageHight:UIImage,frame:CGRect){
        self.init()
        self.frame = frame
        self.setBackgroundImage(backgroundImageNormal, for: UIControlState.normal)
        self.setBackgroundImage(backgroundImageHight, for: UIControlState.highlighted)
    }
    
    // 提供构造方法,背景图
    convenience init(backgroundImageNormal:UIImage,backgroundImageHight:UIImage){
        self.init()
        self.setImage(backgroundImageNormal, for: .normal)
        self.setImage(backgroundImageHight, for: .highlighted)
        self.sizeToFit()
    }
    
    // 提供构造方法,背景图
    convenience init(imageNameNormal:String,imageNameHight:String){
        self.init()
        self.setImage(UIImage(named: imageNameNormal), for: .normal)
        self.setImage(UIImage(named: imageNameHight), for: .highlighted)
        self.sizeToFit()
    }
    
    // 提供构造方法,背景图
    convenience init(title: String, backgroundImageNormal: UIImage, backgroundImageHight: UIImage, backGroundImageDisable: UIImage){
        self.init()
        self.setTitle(title, for: .normal)
        self.setImage(backgroundImageNormal, for: .normal)
        self.setImage(backgroundImageHight, for: .highlighted)
        self.setImage(backGroundImageDisable, for: .disabled)
        self.sizeToFit()
    }
    
    // 提供文字与背景图片,背景色
    convenience init(titleNormal:String, titleColorNormal:UIColor, titleFontSize:CGFloat, backgroundImageNormal:String,backgroundImageHight:String, frame:CGRect){
        self.init()
        self.setTitle(titleNormal, for: UIControlState.normal)
        self.setTitleColor(titleColorNormal, for: UIControlState.normal)
        self.titleLabel?.font = UIFont.systemFont(ofSize: titleFontSize)
        self.frame = frame
        self.setBackgroundImage(UIImage(named:backgroundImageNormal)!, for: UIControlState.normal)
        self.setBackgroundImage(UIImage(named:backgroundImageHight)!, for: UIControlState.highlighted)
    }
    
    // 提供全部构造方式
    convenience init(titleNormal:String, titleHighlighted:String, titleColorNormal:UIColor, titleColorHighLighted:UIColor,titleFontSize:CGFloat,frame:CGRect, backgroundImageNormal:UIImage,backgroundImageHight:UIImage){
        self.init()
        self.setTitle(titleNormal, for: UIControlState.normal)
        self.setTitle(titleHighlighted, for: UIControlState.highlighted)
        self.setTitleColor(titleColorNormal, for: UIControlState.normal)
        self.setTitleColor(titleColorHighLighted, for: UIControlState.highlighted)
        self.titleLabel?.font = UIFont.systemFont(ofSize: titleFontSize)
        self.setBackgroundImage(backgroundImageNormal, for: UIControlState.normal)
        self.setBackgroundImage(backgroundImageHight, for: UIControlState.highlighted)
        self.frame = frame
    }

}
